#include <string.h>

#include "raid.h"

#define FALSE 0
#define TRUE 1

int assert_equals(int arg1, int arg2)
{
	return (arg1 == arg2);
}
int assert_string_equals(char *arg1, char *arg2)
{
	return !strcmp(arg1, arg2);
}

/* Check the read operation on fifo
 */
int test_blockscount()
{
	unsigned long count = blockcount("/dev/loop0");
	if(!assert_equals(2880, count))
		return !printf ("FAILED: %s line %d\n", __func__, __LINE__-1);

	count = blockcount("/dev/loop1");
	if(!assert_equals(2880, count))
		return !printf ("FAILED: %s line %d\n", __func__, __LINE__-1);

	count = blockcount("/dev/loop2");
	if(!assert_equals(2880, count))
		return !printf ("FAILED: %s line %d\n", __func__, __LINE__-1);

	return TRUE;
}

/**
 * Check that the program exits successfully
 */
/*int test_cleanup()
{
	int ret = open("chatlock", O_RDONLY | O_CREAT | O_EXCL, 0600);
	cleanup(-1);
	ret = open("chatlock", O_RDONLY | O_CREAT | O_EXCL, 0600);
	if(ret <= 0) 
		return !printf ("Error: %s @line %d\n", __func__, __LINE__-1);

	return TRUE;
}*/

int main(int argc, char* argv[])
{
	printf ("=== proctree unit test begin ===\n\n");

	int passed = 0;
	int failed = 0;

	test_blockscount() ? passed++ : failed++;
	//test_fifo_write() ? passed++ : failed++;
	
	printf ("\n%d test(s) passed\n", passed);
	printf ("%d test(s) failed\n", failed);
	printf ("\n=== proctree unit test end ===\n");

	return 0;
}
